from django.db import models


class Equipment(models.Model):
    """
    设备资源模型
    """
    organization = models.CharField(max_length=100, verbose_name='组织')
    device_name = models.CharField(max_length=100, verbose_name='设备名称')
    device_quantity = models.IntegerField(verbose_name='设备数量')
    single_device_capacity = models.IntegerField(verbose_name='单设备容量', default=1)
    device_capacity = models.IntegerField(verbose_name='总设备容量')
    created_at = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    updated_at = models.DateTimeField(auto_now=True, verbose_name='更新时间')

    class Meta:
        verbose_name = '设备资源'
        verbose_name_plural = '设备资源'
        db_table = 'equipment'

    def save(self, *args, **kwargs):
        # 前端会自动计算并传递device_capacity值，后端不需要自动计算
        super().save(*args, **kwargs)

    def __str__(self):
        return f'{self.organization} - {self.device_name}'
